package com.xcode.unit.model;

import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import org.apache.commons.lang3.StringUtils;
import org.springframework.util.ObjectUtils;

import java.io.Serializable;
import java.util.List;
import java.util.Map;

/**
 * @author liuziying
 * @Description 源代码模型
 * @Date 2020/12/25
 */
public class SourceClassModel implements Serializable {

    private String packageName;
    private String className;
    private String comment;
    private Map<String, String> importStatics = Maps.newHashMap();
    private Map<String, String> importGenerals = Maps.newHashMap();
    /**
     * 需要Mock的字段
     */
    private List<FieldModel> fieldModels = Lists.newArrayList();

    /**
     * 实例化的变量
     */
    private Map<String, FieldModel> instantiateFieldModels = Maps.newHashMap();

    private List<String> methodNames = Lists.newArrayList();
    private Map<String, MethodModel> methodModels = Maps.newHashMap();

    public MethodModel getMethodModelByName(String name){
        return methodModels.get(name);
    }

    public String getImportStaticByName(String name){
        return importStatics.get(name);
    }

    public String getImportGeneralByName(String name){
        return importGenerals.get(name);
    }

    public boolean existImport(String name){
        if(!ObjectUtils.isEmpty(importGenerals.get(name)) || !ObjectUtils.isEmpty(importStatics.get(name))){
            return true;
        }
        return false;
    }

    public FieldModel getFieldModel(String name){
        for (FieldModel fieldModel : fieldModels) {
            if(StringUtils.equals(name, fieldModel.getName())){
                return fieldModel;
            }
        }
        return null;
    }

    public String getPackageName() {
        return packageName;
    }

    public void setPackageName(String packageName) {
        this.packageName = packageName;
    }

    public String getClassName() {
        return className;
    }

    public void setClassName(String className) {
        this.className = className;
    }


    public String getComment() {
        return comment;
    }

    public void setComment(String comment) {
        this.comment = comment;
    }

    public List<FieldModel> getFieldModels() {
        return fieldModels;
    }

    public void setFieldModels(List<FieldModel> fieldModels) {
        this.fieldModels = fieldModels;
    }

    public Map<String, String> getImportStatics() {
        return importStatics;
    }

    public void setImportStatics(Map<String, String> importStatics) {
        this.importStatics = importStatics;
    }

    public Map<String, String> getImportGenerals() {
        return importGenerals;
    }

    public void setImportGenerals(Map<String, String> importGenerals) {
        this.importGenerals = importGenerals;
    }

    public Map<String, MethodModel> getMethodModels() {
        return methodModels;
    }

    public void setMethodModels(Map<String, MethodModel> methodModels) {
        this.methodModels = methodModels;
    }

    public List<String> getMethodNames() {
        return methodNames;
    }

    public void setMethodNames(List<String> methodNames) {
        this.methodNames = methodNames;
    }

    public Map<String, FieldModel> getInstantiateFieldModels() {
        return instantiateFieldModels;
    }

    public void setInstantiateFieldModels(Map<String, FieldModel> instantiateFieldModels) {
        this.instantiateFieldModels = instantiateFieldModels;
    }
}
